package primitives;

import javax.vecmath.Vector2d;
import javax.vecmath.Vector3d;

import shaders.MatteShader;
import shaders.Shader;


public class Cube extends Mesh {
	private Vector3d center;
	private double length;

	public Cube(Vector3d center, double length) {
		this.length = length;
		this.center = new Vector3d(center);
		this.shader = new MatteShader();

		double dist = length / 2;

		Vector3d[] vertices = {
				new Vector3d(-dist, dist, dist),	// 0    4__________5
				new Vector3d(dist, dist, dist),		// 1    /|        /|
				new Vector3d(dist, -dist, dist),	// 2  0/_|______1/ |
				new Vector3d(-dist, -dist, dist),	// 3   | |      |  |
				new Vector3d(-dist, dist, -dist),	// 4   |7|______|__|6 y ^
				new Vector3d(dist, dist, -dist),	// 5   | /      | /     |
				new Vector3d(dist, -dist, -dist),	// 6   |/_______|/      +-->
				new Vector3d(-dist, -dist, -dist)	// 7  3         2    z /    x
		};

		for (int i = 0; i < vertices.length; i++) {
			vertices[i].add(center);
		}

		int indices[] = {
				0, 1, 2,
				2, 3, 0,
				1, 5, 6,
				6, 2, 1,
				4, 0, 3,
				3, 7, 4,
				4, 5, 1,
				1, 0, 4,
				3, 2, 6,
				6, 7, 3,
				5, 4, 7,
				7, 6, 5
		};

		Vector2d uvs[] = {
			new Vector2d(0, 0),
			new Vector2d(1, 0),
			new Vector2d(1, 1),
			new Vector2d(0, 1),
			new Vector2d(1, 0),
			new Vector2d(0, 0),
			new Vector2d(0, 1),
			new Vector2d(1, 1)
		};

		super.set(vertices, indices, uvs, vertices);
		super.recalcSpacePartition();
	}

	public String toString() {
		return "Cube(" + center + ", " + length + ")";
	}
}
